/*
 * costotogo.c
 *
 * Code generation for function 'costotogo'
 *
 * C source code generated on: Wed Jun 11 17:43:10 2014
 *
 */

/* Include files */
#include "rt_nonfinite.h"
#include "costotogo.h"

/* Function Definitions */
double costotogo(const double x1[14])
{
  double bv[14];
  double xp1[14];
  int k;
  static const double settings_gain[14] = { 0.0503347259274173,
    0.100746453646753, 0.318339540954382, 0.0937262730471322, 1.00000001331555,
    1.00000001232309, 0.0161954232020047, 0.048674631504831, 0.0489152114004245,
    0.16004296346025, 0.160077394139578, 9.53215194851665E-5,
    0.00852060285155151, 0.00883521305980648 };

  static const double settings_xoffset[14] = { -19.906, -9.88031, -3.1412,
    0.0582494635168442, -0.999999981442297, -0.999999994625933,
    -61.6672734555919, -20.4640483845939, -20.6576499191031, -9.38819215567605,
    -9.41107078716557, -1482.89654834504, -177.890385842624, -172.530246470464 };

  double av[14];
  int ib;
  int ia;
  static const double a[14] = { 1.9314044409184716, -1.0927069255360222,
    -1.6185083943202205, 0.052235474059689993, 0.55991308266831519,
    0.0039079879664824114, -0.75947815749028258, 0.024742286863746528,
    -0.41210820377094148, 0.29857072123268341, 1.6087253374469106,
    -0.72004436861200449, -0.80517686221416285, -2.4279541881361255 };

  double b_av[14];
  double y;
  static const double b_a[196] = { -0.063257069131583687, 3.6249581414113958,
    -0.007944349213196273, -1.3080658012004671, 0.60560082071912358,
    -0.8312288471502095, 0.14490444770004271, -0.86880044969651415,
    0.39084241896053107, 3.6159556967020725, -0.064537725959294925,
    0.094153596325859526, -0.14256362514167081, -0.31408494887943672,
    0.068208485774226765, 1.0583997670749414, -0.16191883433372942,
    -0.50665665399345816, -1.1365488974272924, -0.76386446169944866,
    0.13229895200772324, -0.31369700192208272, -1.7196858969498483,
    -0.68294369850447012, 0.065585767661644853, 0.075865974658648971,
    -0.044830399813308261, 0.98989355355437136, -0.2970952824096858,
    0.15999276551928709, -0.017037496929640534, -0.0028330578024241397,
    0.099094799808767772, 0.67616681820690094, -0.031667073130484613,
    -0.41117973179909884, 0.011945779231072836, 0.080757917983826782,
    -0.32827978452428513, -0.023654243282460553, 0.01406986756442089,
    -0.55886438088591039, 0.28185232126115894, 0.002061015734793102,
    0.2814671452517935, -0.77481693219478576, 0.2704360587358397,
    -0.082336955795199882, 0.004313029791064178, -0.36544741320580137,
    -0.07102795278024554, 0.033661382192243135, 0.11746554542627724,
    0.0570852676729263, 0.13329897910041436, -0.21870726520009748,
    0.039584227494056316, 0.35653490064488214, -0.27437246900503337,
    -0.19991205104994705, 0.19426910475684939, -0.10732365991776953,
    -0.12439156964224557, -0.11286832639064225, 0.042782590617823184,
    0.41679017216331593, -0.0084240332352075713, -0.080086166879665133,
    0.094084623796948916, 0.32645655251915989, -0.29323884410338913,
    0.16036351239020441, 0.49612045440187497, -0.40489211606264969,
    -0.36867328575333758, -0.32813420345927546, -0.25627354220286291,
    0.0337246608962615, -0.49382738327169018, -0.20559037623982498,
    -0.28796387434587245, -0.14709957578363425, 0.075860881993684043,
    -1.0718358724628465, -0.0990713739155948, -0.16649549441311312,
    0.014710822971095957, 0.36835602609054546, -0.032339836795863969,
    1.6809333636427746, -0.015429387384928505, -0.36137615852807592,
    0.049034649884208414, -0.19159169223400546, 0.052307387774242292,
    -0.00773364867517922, 0.014743292423716104, 0.28878614163892258,
    -0.048050583221277719, 3.1004582038873227, 0.032743048885811976,
    -1.114700370938551, 0.5577267407081633, 0.21975231771029616,
    -0.033931883425634975, -1.2514468024750656, 0.2663931243064267,
    2.7650805584947395, -0.0582562269671247, -0.026481920632007803,
    0.064442057768009167, 0.086843004132728649, 0.009259331325028413,
    1.8333147799013325, -0.16905128995448265, -0.60316058169429054,
    -1.84008799852262, -1.0048411325278044, 0.12863042688584231,
    -0.761880968066331, -2.53273359575866, -0.95955686346635527,
    0.063748054978813626, 0.069279046500210772, -0.053739836659387627,
    0.644019646422121, -0.0002456164174342781, 0.01732979014711216,
    0.0036821883812481761, 0.01056964338931247, 0.0019633083645704714,
    0.018584880004638607, 0.00028255160490637393, 0.016123507704927226,
    -0.026829098743664341, -0.012220801621079379, -0.00014635912670311527,
    9.0822791950915815E-6, 0.00019747031924765773, 0.012692143978236384,
    0.0013737375582127758, 0.0098378215337864561, 0.0044114167586565712,
    -0.011254369053416598, -0.0095098255110270171, 0.017801851627868188,
    0.00077232825251118673, 0.019773746430652942, -0.019066073965027,
    0.00066660168784692044, 0.0017277221397607359, 0.00023902977527167263,
    0.00041833061789840146, 0.0014126769447541081, -0.12039105452837999,
    -0.44286387489916262, 0.01000680446216796, 0.86580514368742989,
    0.17804880373842127, 0.23929462290101863, -0.071734827755437214,
    -0.35519317347418311, 0.23860144176361603, -0.14769091477598828,
    -0.11843694390944584, -0.037860209701408937, 0.00558200341255829,
    0.36860813718189273, -0.0013286046582568337, -0.041667131115250909,
    -0.00045905830905112484, -0.016644282155716016, -0.020389214439378332,
    -0.043579964390855923, -0.0033191806774490813, -0.016973355340293646,
    0.04251925538755276, 0.010236187331417053, -0.00034968321855928649,
    -0.0016018347062648809, 0.0010943721914468208, -0.027401040036820024,
    -0.0022264311192201052, -0.0039068307966603011, -0.0024876872839580005,
    0.026061219553689376, 0.0082509253014538576, -0.037373817710262908,
    -0.00405384513758634, -0.017941391549960384, 0.015949221294124703,
    -0.0035179926507316814, -0.0021552642738290584, -0.0020013168084900392,
    0.00099540835423030712, -0.010417893486878623 };

  double b[4];
  static const double c_a[4] = { 1.3579608899541953, 0.26654017891017218,
    -0.725421634171925, -2.8322991528795778 };

  double b_b[4];
  static const double d_a[56] = { 2.0362886303996786, 1.6523851959220284,
    -0.72329096919857316, -1.9805224779307746, 0.00055145216938164534,
    -0.30775000405101083, -2.3894192967896259, -5.3685783618006306,
    0.26522236204867694, 1.2207067730276622, 3.5828453729295662,
    1.2230361093964897, 0.0015726515849015263, -0.70561945392233216,
    -0.11337789633774378, 2.0623801748292947, 0.011599569943619766,
    -0.60076725115127028, 1.1367403707704682, 0.58770723601784669,
    0.004182943352637053, 0.09571753704495406, 0.21371573232360619,
    -0.74801304227089693, -1.1871087654590839, 0.44621512590713586,
    0.75062601234271986, 0.20046022031976635, -0.0071215576763787418,
    0.55196646705549046, 0.96959267589102072, -1.6481828391955353,
    -0.0087445549305949031, 0.50908515176042135, -1.2357783259236523,
    -5.6019584527492263, 0.0010888008974598471, -0.11218994282434275,
    -0.83723777326823123, 4.4634587443772649, -1.6411966651301029,
    0.15713795300867456, -0.0580530216836264, -1.4495331398823319,
    2.6765263862998365, -0.499696445263937, -1.5168626451214311,
    1.001235634845439, 0.72457627003177671, 0.93239658684530846,
    -0.01635383048216392, 2.8655894713209604, 0.028415183101462078,
    -0.48169090644926205, 1.1544436895135726, -0.38267451870212071 };

  static const double dv0[4] = { 5.5612628927474548, 0.09474257227032247,
    -0.028167106409981071, 1.771860387468587 };

  /* COSTOTOGO neural network simulation function. */
  /*  */
  /*  Generated by Neural Network Toolbox function genFunction, 11-Jun-2014 17:34:46. */
  /*   */
  /*  [y1] = costotogo(x1) takes these arguments: */
  /*    x = 14xQ matrix, input #1 */
  /*  and returns: */
  /*    y = 1xQ matrix, output #1 */
  /*  where Q is the number of samples. */
  /*  ===== NEURAL NETWORK CONSTANTS ===== */
  /*  Input 1 */
  /*  Layer 1 */
  /*  Layer 2 */
  /*  Layer 3 */
  /*  Output 1 */
  /*  ===== SIMULATION ======== */
  /*  Dimensions */
  /*  samples */
  /*  Input 1 */
  /*  ===== MODULE FUNCTIONS ======== */
  /*  Map Minimum and Maximum Input Processing Function */
  for (k = 0; k < 14; k++) {
    bv[k] = settings_gain[k];
    xp1[k] = (x1[k] - settings_xoffset[k]) * settings_gain[k] + -1.0;
  }

  /*  Layer 1 */
  ib = 0;
  ia = 0;
  for (k = 0; k < 14; k++) {
    av[ib] = a[ia];
    ia++;
    ib++;
  }

  /*  Sigmoid Symmetric Transfer Function */
  for (k = 0; k < 14; k++) {
    y = 0.0;
    for (ib = 0; ib < 14; ib++) {
      y += b_a[k + 14 * ib] * xp1[ib];
    }

    b_av[k] = av[k] + y;
  }

  for (k = 0; k < 14; k++) {
    bv[k] = exp(-2.0 * b_av[k]);
  }

  /*  Layer 2 */
  ib = 0;
  ia = 0;
  for (k = 0; k < 4; k++) {
    b[ib] = c_a[ia];
    ia++;
    ib++;
  }

  /*  Sigmoid Symmetric Transfer Function */
  for (k = 0; k < 14; k++) {
    xp1[k] = 2.0 / (1.0 + bv[k]) - 1.0;
  }

  for (k = 0; k < 4; k++) {
    y = 0.0;
    for (ib = 0; ib < 14; ib++) {
      y += d_a[k + (ib << 2)] * xp1[ib];
    }

    b_b[k] = b[k] + y;
  }

  /*  Layer 3 */
  y = 0.0;
  for (k = 0; k < 4; k++) {
    y += dv0[k] * (2.0 / (1.0 + exp(-2.0 * b_b[k])) - 1.0);
  }

  /*  Output 1 */
  /*  Map Minimum and Maximum Output Reverse-Processing Function */
  return ((0.77747122921454248 + y) - -1.0) / 0.0975588293155111 + 0.098549;
}

/* End of code generation (costotogo.c) */
